package com.nuoniu.sibanyun.controller.crm;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.common.web.http.HttpClientUtils;
import com.nuoniu.sibanyun.entity.crm.CrmGoods;
import com.nuoniu.sibanyun.entity.crm.CrmGoodsConfig;
import com.nuoniu.sibanyun.service.crm.ICrmGoodsConfigService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品配置 前端控制器
 * </p>
 *
 * @author baiqiang
 * @since 2020-07-20
 */
@RestController
@RequestMapping("/member/config")
@Api(tags = "商品配置")
public class CrmGoodsConfigController extends BaseController {

    @Autowired
    private ICrmGoodsConfigService goodsConfigService;

    /**
     * 获取产品配置列表
     * @author 小啊刚
     * @date 2020-07-23
     */
    @GetMapping("list")
    public HttpResult getGoodsConfigList() {
        return HttpResult.ok(goodsConfigService.getGoodsConfigList());
    }

    /**
     * 获取产品配置列表
     * @author 小啊刚
     * @date 2020-07-23
     */
    @GetMapping("goodsConfigList")
    public HttpResult goodsConfigList() {
        return HttpResult.ok(goodsConfigService.goodsConfigList());
    }

    /**
     * 保存商品配置
     * @author 小啊刚
     * @date 2020-07-23
     */
    @PostMapping("save")
    public HttpResult saveGoodsConfig(@RequestBody CrmGoodsConfig goodsConfig) {
        goodsConfigService.saveOrUpdate(goodsConfig);
        return HttpResult.ok();
    }

    /**
     * 停用商品
     * @author 小啊刚
     * @date 2020-07-17
     */
    @PostMapping("disable")
    public HttpResult disable(@RequestBody List<Long> ids) {
        for(Long id : ids) {
            CrmGoodsConfig goodsConfig = new CrmGoodsConfig();
            goodsConfig.setId(id);
            goodsConfig.setStatus(2);
            goodsConfigService.updateById(goodsConfig);
        }
        return HttpResult.ok();
    }

    /**
     * 启用商品
     * @author 小啊刚
     * @date 2020-07-17
     */
    @PostMapping("enable")
    public HttpResult enable(@RequestBody List<Long> ids) {
        for(Long id : ids) {
            CrmGoodsConfig goodsConfig = new CrmGoodsConfig();
            goodsConfig.setId(id);
            goodsConfig.setStatus(0);
            goodsConfigService.updateById(goodsConfig);
        }
        return HttpResult.ok();
    }
}
